package lt.marsrutai.mobile.android.activity;

import lt.marsrutai.mobile.android.R;
import lt.marsrutai.mobile.android.activity.intent.SchedulesIntentHolder;
import lt.marsrutai.mobile.android.activity.intent.StopsIntentHolder;
import lt.marsrutai.mobile.android.activity.intent.TracksIntentHolder;
import lt.marsrutai.mobile.android.fragment.StopsFragment;
import android.content.Intent;
import android.support.v4.app.ListFragment;

public class StopsActivity extends BaseActivity {

    @Override
    public boolean onNavigationItemSelected(int itemPosition, long itemId) {
        StopsIntentHolder sourceIntentHolder = new StopsIntentHolder(getIntent());

        switch (itemPosition) {
        case 1:
            TracksIntentHolder tracksintentHolder = new TracksIntentHolder(this,
                sourceIntentHolder.getScopeFolder(),
                sourceIntentHolder.getScopeName(),
                sourceIntentHolder.getTransportId(),
                sourceIntentHolder.getScheduleId(),
                sourceIntentHolder.getScheduleName(),
                sourceIntentHolder.getScheduleTrackName()
            );
            startActivity(tracksintentHolder.getIntent());
            break;
        case 2:
            SchedulesIntentHolder schedulesIntentHolder = new SchedulesIntentHolder(this);
            schedulesIntentHolder.setScopeFolder(sourceIntentHolder.getScopeFolder());
            schedulesIntentHolder.setScopeName(sourceIntentHolder.getScopeName());
            startActivity(schedulesIntentHolder.getIntent());
            break;
        case 3:
            startActivity(new Intent(this, ScopesActivity.class));
            break;
        default:
            return false;
        }

        return false;
    }

    @Override
    public NavMenuData getNavMenuData() {
        StopsIntentHolder intentHolder = new StopsIntentHolder(getIntent());
        return new NavMenuData(new String[] { intentHolder.getTrackName(), intentHolder.getScheduleTrackName(),
                intentHolder.getScopeName(), getString(R.string.home) }, intentHolder.getScheduleName(), 1,
                intentHolder.getScopeFolder(), intentHolder.getTransportId());
    }

    @Override
    public void setupView() {
        if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
            ListFragment fragment = new StopsFragment();
            fragment.setArguments(getIntent().getExtras());
            getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit();
        }
    }

}
